const { DataTypes } = require('sequelize')

const seq = require('../db/seq')

const Course = seq.define('edu_course', {
  title: {
    type: DataTypes.STRING(30),
    allowNull: false,
    comment: '课程标题'
  },
  cat_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '课程分类ID'
  },
  teacher: {
    type: DataTypes.STRING(40),
    allowNull: false,
    //后续优化为讲师ID
    comment: '课程讲师姓名'
  },
  lesson_num: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '总课时'
  },
  brief: {
    type: DataTypes.STRING(100),
    allowNull: false,
    default: '',
    comment: '课程简介，不超过100字'
  },
  cover_url: {
    type: DataTypes.STRING,
    allowNull: true,
    comment: '课程封面地址'
  },
  discounts: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '课程售卖价格'
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '课程原价'
  },
  sales: {
    type: DataTypes.BIGINT,
    allowNull: true,
    defaultValue: 0,
    comment: '销售数量'
  },
  discountsTag: {
    type: DataTypes.STRING(20),
    allowNull: true,
    default: '',
    comment: '活动标签，不超过10个字'
  },
  details: {
    type: DataTypes.STRING(100),
    default: '',
    comment: '课程详情，不超过100字'
  },
  view_count: {
    type: DataTypes.BIGINT,
    defaultValue: 0,
    comment: '课程详情'
  },
  version: {
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: 1,
    comment: '乐观锁'
  },
  status: {
    type: DataTypes.STRING(10),
    allowNull: false,
    defaultValue: 'Draft',
    comment: 'Draft未发布  Normal已发布'
  },
  is_deleted: {
    type: DataTypes.TINYINT,
    allowNull: false,
    defaultValue: 0,
    comment: '逻辑删除 1（true）已删除， 0（false）未删除'
  }
})

//Course.sync({ alter: true })

module.exports = Course
